import {makeAutoObservable, runInAction} from "mobx";
import {TInitFlag} from "@/common/common";
import {apiQueryCalibrateListData} from "@/common/apis/radar";
import _ from "lodash";

class FusionStore {
  constructor() {
    makeAutoObservable(this)
  }

  initialFlg: TInitFlag = "initial";
  calibrateList: any[] = [];

  // 查
  queryCalibrateList = async (params?: any) => {
    if (!_.isEmpty(this.calibrateList)) {
      return this.calibrateList;
    }
    if (this.initialFlg !== "initial") {
      return;
    }
    this.initialFlg = "initialing";
    const res = await apiQueryCalibrateListData({});
    runInAction(() => {
      if (res.code === 0) {
        this.calibrateList = res.data || [];
      }
      this.initialFlg = "initial";
    })
  }

  get getCalibrateList() {
    if (this.calibrateList.length <= 0) {
      this.queryCalibrateList();
      return this.calibrateList;
    }
    return this.calibrateList;
  }
}

export default new FusionStore()
